/*!
    \copyright  Copyright (c) 2019 - 2025 Qualcomm Technologies International, Ltd.\n
                All Rights Reserved.\n
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup handset_service
    @{
    \brief      Configurable values for the Handset Service.
*/

#ifndef HANDSET_SERVICE_CONFIG_H_
#define HANDSET_SERVICE_CONFIG_H_

#include "handset_service.h"
#include "rtime.h"


#define PAGE_TIMEOUT_IN_MS ((rtime_t) 5120)


/*! Maximum permitted number of BR/EDR ACL connections
*/
#define HANDSET_SERVICE_MAX_PERMITTED_BREDR_CONNECTIONS 2

/*! Maximum permitted number of LEA ACL connections
*/
#define HANDSET_SERVICE_MAX_PERMITTED_LEA_CONNECTIONS 2

/*! The delay period after the maximum number of BREDR ACLs/LE ACLs being connected before the
    Handset Service shall attempt to enable Truncated Page Scan/Truncated LE connectable adverts.
    This delay is designed to allow time for the Handset that has caused us to hit the maximum
    number of BREDR/LE ACLs threshold to connect all its profiles before we allow another handset
    to barge-in. */
#ifndef HANDSET_SERVICE_PROFILE_CONNECTION_GUARD_PERIOD_MS
#define HANDSET_SERVICE_PROFILE_CONNECTION_GUARD_PERIOD_MS    30000
#endif

#ifdef ENABLE_CONSOLIDATED_HANDSET_COUNT
#ifndef ENABLE_PEER_FIND_ROLE_ACCEPTOR_LIST
#error ENABLE_CONSOLIDATED_HANDSET_COUNT requires ENABLE_PEER_FIND_ROLE_ACCEPTOR_LIST
#endif
#define HANDSET_DEFAULT_ENABLE_CONSOLIDATED_HANDSET_COUNT (TRUE)
#else
#define HANDSET_DEFAULT_ENABLE_CONSOLIDATED_HANDSET_COUNT (FALSE)
#endif /* ENABLE_CONSOLIDATED_HANDSET_COUNT */

#define HANDSET_SERVICE_FAST_PAGE_SCAN_TIMEOUT_MS 5000

/*! Time to stop advertising for when a device connects that could pair

    The advertising suspension will finish earlier if pairing completes.
 */
#define handsetService_AdvertisingSuspensionForPairingMs() (5000)

/*! Time delay between each handset ACL connect retry.

    The delay is in ms.
*/
#define handsetService_BredrAclConnectRetryDelayMs() (500)

/*! Maximum allowed duration for directed advertising.
    If the targeted device did not connect within this duration,
    directed advertising will be stopped.

    The delay is in ms.
*/
#define HANDSET_SERVICE_DIRECTED_ADVERTS_TIMEOUT_MS 15000

/*! Maximum allowed duration for directed advertising after a disconnection caused by a link loss.
    If the targeted device did not connect within this duration after a link loss, directed
    advertising will be stopped.

    The delay is in ms.
*/
#define HANDSET_SERVICE_DIRECTED_ADVERTS_LINK_LOSS_TIMEOUT_MS 30000

/*! \brief HCI disconnect reason code to use when a handset needs to be disconnected
           in barge in scenarios (common for both LE and BREDR barge in).
*/
#ifndef HANDSET_SERVICE_BARGE_IN_DISCONNECT_HCI_REASON_CODE
#define HANDSET_SERVICE_BARGE_IN_DISCONNECT_HCI_REASON_CODE      (HCI_ERROR_OETC_LOW_RESOURCE)
#endif

#ifdef HANDSET_SERVICE_CONFIG_OPTION_EXIT_PAIRING_MODE_ON_FAILURE
#define EXIT_PAIRING_MODE_ON_FAILURE HANDSET_SERVICE_CONFIG_OPTION_EXIT_PAIRING_MODE_ON_FAILURE
#else
#define EXIT_PAIRING_MODE_ON_FAILURE FALSE
#endif

/*! \brief Set the maximum number of handset ACL connect requests to attempt.

    \param num_attempts the maximum number of connection attemtpts
*/
bool handsetService_SetBredrAclConnectAttemptLimit(uint8 num_attempts);

/*! Maximum permitted number of BR/EDR ACL connections

    Can be modified using HandsetService_Configure.
*/
uint8 handsetService_BredrAclMaxConnections(void);

/*! \brief Check if connection barge-in is enabled

    \return TRUE if enabled, FALSE if disabled.
*/
bool handsetService_IsConnectionBargeInEnabled(void);

/*! Handle creation of the SELF device

  This is the time when data can be stored in the device database.
*/
void handsetService_HandleSelfCreated(void);

/*! Handle update of handset_service_config property
    It is expected to be called on the secondary earbud.
*/
void handsetService_HandleConfigUpdate(void);

/*! Maximum permitted number of LE ACL connections
*/
uint8 handsetService_LeAclMaxConnections(void);

/*! Maximum permitted number of consolidated handset connections.

    \note A consolidated handset is a handset that is connected over BR/EDR, LE or both.
*/
uint8 handsetService_GetMaxConsolidatedHandsetConnections(void);


/*! \brief Test whether unlimited ACL reconnection attempts are currently enabled.
 *
 *  \return TRUE if unlimited ACL reconnections are enabled, FALSE otherwise.
 */
bool handsetService_IsUnlimitedAclReconnectionEnabled(void);


/*! \brief Get the currently configured page timeout used for initial reconnection.
 *
 *  \return the initial reconnection page timeout in ms.
 */
uint16 handsetService_GetInitialReconnectionPageTimeout(void);

/*! \brief Get the interval between page scan attempts that the Handset Service is using for
 *         unlimited ACL reconnections.
 *
 *  \return the page interval in ms.
 */
uint32 handsetService_GetUnlimitedReconnectionPageInterval(void);

/*! \brief Get the currently configured page timeout the Handset Service shall use when
 *         performing infinite link loss reconnection.
 *
 *  \return the page timeout in ms, for unlimited reconnection.
 */
uint16 handsetService_GetUnlimitedReconnectionPageTimeout(void);

/*! Initialise handset service configuration to defaults
*/
void HandsetServiceConfig_Init(void);

uint32 HandsetService_CalculatePageIntervalMsValue(uint8 page_interval_config);

/*! \brief Get the Handset Service configuration data
 *  \return pointer to structure for Handset service configuration data.
 */
handset_service_config_t *handsetService_GetConfig(void);

/*! \brief Check whether abort_on_failed_pairing TRUE/FALSE.
 *
 *  \return TRUE if enabled, FALSE otherwise.
 */
bool handsetService_IsAbortOnFailedPairingEnabled(void);

/*! \brief Get pairing_timeout_user_s in seconds for user initiated pairing
 *
 *  \return timout in sec.
 */
uint32 handsetService_GetPairingTimeoutUser(void);

/*! \brief Get pairing_timeout_automatic_s in seconds for automatic pairing
 *
 *  \return timout in sec.
 */
uint32 handsetService_GetPairingTimeoutAutomatic(void);

#endif /* HANDSET_SERVICE_CONFIG_H_ */
/*! @} */
